package com.site.service;

import com.site.domain.User;
import com.site.enums.ResultEnum;
import com.site.exception.UserException;
import com.site.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by shengquan.wu on 2018/6/5.
 */
@Service
public class UserService {

    @Autowired
    private UserRepository userRepository;


    public void getAge(Integer id) throws Exception {
        User user = userRepository.findOne(id);
        Integer age = user.getAge();
        if(age<10){
            //返回 在上小学
            throw new UserException(ResultEnum.PRIMARY_SCHOOL);
        }else if(age>10 && age <16){
            //返回 在上初中
            throw new UserException(ResultEnum.MIDDLE_SCHOOL);
        }
    }

    /**
     *
     * @param id
     * @return
     */
    public User findOne(Integer id){
        return userRepository.findOne(id);
    }

}
